<template>
  <view class="container">
    <view class="head">
      <view class="title">{{state.detail?.order_no}}{{state.detail?.name}}</view>  
    </view>
    <view class="content">
      <view class="title">
        <uni-icons type="left" size="30" class="icon" @click="goBack"></uni-icons>
        <view class="titleRight">
          <view class="span">{{state.detail?.order_no}}</view>
          <view class="span">{{state.detail?.name}}</view>
        </view> 
      </view>
      <view class="bottom">
        <CommonTitle :orderInfo="state.detail"/>
        <view class="body">
          <view class="line"></view>
          <view class="formMain" v-if="state.tabId == 2">
            <view class="formTitle">老师修改完登记</view>
            <view class="formItem" v-for="(item, index) in state.msgContent" :key="index">
              <view class="label">消息{{convertToChinese(index+1)}}</view>
              <view class="formItemRight">
                <uni-easyinput type="textarea" autoHeight :value="item" placeholder="请输入内容" @blur="changeInput($event,index)"/>
              </view>
              <uni-icons type="minus" size="30" class="iconClose" color="rgba(254, 34, 34, 1)" v-if="state.msgContent?.length > 1" @click="deleteFun(index)"></uni-icons>
            </view> 
            <view class="addBtn" @click="clickAdd">+</view>
            <view class="submitBtn" @click="submit">确认转发</view>
          </view>
          <view class="formMain" v-if="state.tabId == 1">
            <view class="formTitle">学生修改要求</view>
            <view class="formItem" v-for="(item, index) in state.msgContent" :key="index">
              <view class="label">消息{{convertToChinese(index+1)}}</view>
              <view class="formItemRight">
                <uni-easyinput type="textarea" autoHeight :value="item" placeholder="请输入内容"/>
              </view>
              <uni-icons type="minus" size="30" class="iconClose" color="rgba(254, 34, 34, 1)" v-if="state.msgContent?.length > 1" @click="deleteFun(index)"></uni-icons>
            </view> 
            <view class="addBtn" @click="clickAdd">+</view>
            <view class="submitBtn" @click="submit">确认转发</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
  import { onLoad } from '@dcloudio/uni-app'
  import { reactive } from 'vue'
  import CommonTitle from '@/components/commonTitle.vue'
  import { convertToChinese } from '@/utils/contanst.js'
  import { adminSendMsg } from '@/utils/admin.js'
  const state = reactive({
    detail: null,
    msgContent: [],
    isShowTeacher: false,
    tabId: null
  })
  onLoad((options) => {
    if (options?.itemInfo) {
      state.detail = JSON.parse(options?.itemInfo)
      state.msgContent = JSON.parse(options?.itemInfo)?.content
      state.tabId = options.tabId
    }
  })
  const goBack = () => {
    uni.navigateBack()
  }
  const changeInput = (e, index) => {
    console.log(70, e?.detail?.value)
    state.msgContent[index] = e?.detail?.value
  }
  const deleteFun = (index) => {
    state.msgContent.splice(index, 1)
    console.log(80, state.msgContent)
  }
  // 点击加号
  const clickAdd = () => {
    state.msgContent = [...state.msgContent, '']
  }
  const submit = () => {
    let params = {
      id: state.detail?.id,
      content: state.detail?.content
    }
    adminSendMsg(params).then((res) => {
      if (res?.code == 1) {
        console.log(64, res)
        goBack()
      }
    })
  }
</script>

<style lang="scss" scoped>
  .container{
    width: 750rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    .head{
      width: 750rpx;
      height: 198rpx;
      background: radial-gradient(132.09% 132.09% at 50% 47%, rgba(27, 79, 215, 0.48) 0%, #184BC9 46.63%);
      display: flex;
      justify-content: center;
      align-items: center;
      .title{
        font-family: PingFang SC;
        font-weight: 400;
        font-size: 32rpx;
        color: #ffffff;
        width: 700rpx;
        padding-bottom: 10rpx;
      }
    }
    // 内容
    .content{
      width: 674rpx;
      border-radius: 14rpx;
      padding: 20rpx; 
      background: rgba(247, 247, 247, 1);
      margin-top: 20rpx;
      .title{
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2rpx dashed #cccccc;
        padding-bottom: 20rpx;
        .icon{
          margin-left: 20rpx;
        }
        .titleRight{
          width: 574rpx;
          height: 76rpx;
          border-radius: 6rpx;
          background: rgba(209, 243, 241, 1);
          display: flex;
          justify-content: center;
          align-items: center;
          flex-direction: row;
          margin-right: 20rpx;
          .span{
            margin-right: 20rpx;
          }
        }
        .iconClose{
          margin-left: 20rpx;
        }
      }
      .bottom{
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        justify-content: center;
        .labels{
          display: flex;
          flex-direction: row;
          justify-content: space-around;
          align-items: center;
          border-bottom: 2rpx dashed #cccccc;
          width: 100%;
          padding-top:20rpx;
          padding-bottom: 20rpx;
          .span{
            display: flex;
            flex-direction: column;
            align-items: center;
            font-family: HarmonyOS Sans SC;
            font-weight: 400;
            font-size: 12px;
            color: rgba(122,122,122,1);
            min-width: 90rpx;
          }
          .span01{
            width: 236rpx;
          }
        }
        .body{
          width: 100%;
          display: flex;
          flex-direction: column;
          .row{
            width: 650rpx;
            height: 84rpx;
            border-radius: 6rpx;
            display: flex;
            flex-direction: row;
            justify-content: space-around;
            background: rgba(209, 243, 241, 1);
            margin-top:20rpx;
            .span{
              display: flex;
              flex-direction: row;
              align-items: center;
              justify-content: center;
              font-family: HarmonyOS Sans SC;
              font-weight: 400;
              font-size: 28rpx;
              min-width: 90rpx;
              text{
                color: rgba(60, 60, 60, 1);
              }
              .text02{
                font-size: 20rpx;
              }   
            }
            .span01{
              width: 236rpx;
              flex-direction: column;
            }
            .text03{
              width: 28rpx;
              height: 28rpx;
              border-radius: 6rpx;
              border: 2rpx solid rgba(11, 105, 218, 1);
            }
            .text03Hover{
              background: rgba(28, 246, 21, 1);
            }
          }
          .line{
            width: 100%;
            border-bottom: 2rpx dashed rgba(146, 146, 146, 1);
            margin-top: 10rpx;
            margin-bottom: 10rpx;
          }
          .formMain{
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top:30rpx;
            .formTitle{
              width: 100%;
              text-align: center;
              font-family: PingFang SC;
              font-weight: 600;
              font-size: 32rpx;
              color: rgba(101, 115, 233, 1);
            }
            .formItem{
              display: flex;
              flex-direction: row;
              justify-content: flex-start;
              align-items: center;
              margin-top: 20rpx;
              .label{
                width: 90rpx;
                font-family: HarmonyOS Sans SC;
                font-weight: 400;
                font-size: 24rpx;
                color: rgba(122, 122, 122, 1);
              }
              .formItemRight{
                width: 444rpx;
                height: 214rpx;
                overflow: scroll;
              }
            }
            .addBtn{
              width: 362rpx;
              height: 72rpx;
              border-radius: 14rpx;
              border: 2rpx solid rgba(0, 0, 0, 0.28);
              background: rgba(231, 231, 231, 0.59);
              color: rgba(146, 146, 146, 1);
              font-size: 40rpx;
              display: flex;
              justify-content: center;
              align-items: center;
            }
            .submitBtn{
              width: 248rpx;
              height: 74rpx;
              border-radius: 6rpx;
              background: rgba(255, 11, 11, 0.28);
              font-family: HarmonyOS Sans SC;
              font-weight: 400;
              font-size: 48rpx;
              color: rgba(58, 58, 58, 0.68);
              margin-top: 40rpx;
              display: flex;
              justify-content: center;
              align-items: center;
            }
          }
        }
      }
    }
    
  }
</style>